package com.topfinance.cnaps2.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeanUtils;

import com.topfinance.cnaps2.dto.ConfOperationDto;
import com.topfinance.cnaps2.ebo.ConfOperationEbo;
import com.topfinance.cnaps2.service.IOperationManager;
import com.topfinance.frame.dao.HibernateEntityDao;
import com.topfinance.frame.exception.AppException;
import com.topfinance.payment.ebo.TCfgProtocolEbo;

/**
 * 该类自动实现了dao的一般方法，如add, remove, update
 * 在service中出现的大部分情况下是在向后台提交数据前的处理(如校验)及获取后台数据后的处理等
 * @author
 *
 */

public class OperationManagerImpl extends HibernateEntityDao<ConfOperationEbo> implements IOperationManager {

	private static final Log log = LogFactory.getLog(OperationManagerImpl.class);

	public void addOper(ConfOperationDto ot) throws AppException{
		TCfgProtocolEbo po = (TCfgProtocolEbo)get(TCfgProtocolEbo.class,ot.getPID());
		ConfOperationEbo o = new ConfOperationEbo();
		BeanUtils.copyProperties(ot, o);
		o.setPrtclEbo(po);
		save(o);
    }
	
	public void editOper(ConfOperationDto ot) throws AppException{
		TCfgProtocolEbo po = (TCfgProtocolEbo)get(TCfgProtocolEbo.class,ot.getPID());
		ConfOperationEbo o = new ConfOperationEbo();
		BeanUtils.copyProperties(ot, o);
		o.setPrtclEbo(po);
		update(o);
    }
	
	//获得传输协议	
	public ConfOperationEbo getOper(Integer uid) throws AppException{
		return (ConfOperationEbo)get(uid);
	}

	public void deleteOper(ConfOperationDto o) throws AppException{
		removeById(o.getClass(),o.getUid());
    }
	public void deleteOper(Integer id) throws AppException{
		removeById(ConfOperationEbo.class,id);
	}

	//获得传输协议列表
	public List getAllOperList() throws AppException{
		String hql = " from ConfOperationEbo t " ;
		String where = "";
		List<Object> paramList = new ArrayList<Object>();
		if (isNotBlank(where)) {
			where = " where " + where;
		}
		hql = hql + where;
		return find(hql,paramList.toArray());		
	}
}
